import java.util.Stack;

public class MinStack {
    Stack<Integer>stack;
    Stack<Integer>MinStack;
    public MinStack() {
        stack=new Stack<>();
        MinStack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (MinStack.empty()){
            MinStack.push(val);
        }else{
            int stackVal=MinStack.peek();
            if (val<=stackVal){
                MinStack.push(val);
            }
        }
    }

    public void pop() {
        if (stack.empty()){
            return;
        }
        int popVal=stack.pop();
        if (popVal==MinStack.peek()){
            MinStack.pop();
        }
    }

    public int top() {
        if (stack.empty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if (MinStack.empty()){
            return -1;
        }
        return MinStack.peek();
    }
}
